-
Notifications
You must be signed in to change notification settings - Fork 212
Adding support for loading datasets and visualizing model predictions via FiftyOne #360
Conversation
… into feature/fiftyone
… into feature/fiftyone
Alright! This PR is ready for you guys to take a final pass over @ethanwharris @tchaton There is one thing I need your assistance with. In the integration docs I added a video and an image. They would likely be best hosted by you, but I am just unsure what your process is for hosting documentation media. They currently link here: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehofesmann Awesome! Just a few comments, I've added your assets to our S3 and recommended changes with the new links 😃 Could you also update with master and get the tests to pass? Then will be ready to merge
Hey @ehofesmann, just an FYI, you're getting some test failures due to an unrelated dependency issue. I'm working on a fix, I'll let you know when it's in master 😃 |
Gotcha! I was racking my brain trying to figure out what I broke. I'll wait until it's in master 👍 |
@ehofesmann If you update to master the CI should be working properly again 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are passing, LGTM 😃
Awesome! We're just taking a final pass over everything. I'll let you know once we're done and then it's all yours. |
It would be great to make it easier for users to find these visualization capabilities. What do you guys think about me merging in this section to the README? The proposed content: VisualizationPredictions from image and video tasks can be visualized through our integration with FiftyOne from flash.core.data.utils import download_data
from flash.core.integrations.fiftyone import visualize
from flash.image import ObjectDetector
from flash.image.detection.serialization import FiftyOneDetectionLabels
# 1. Download the data
# Dataset Credit: https://www.kaggle.com/ultralytics/coco128
download_data(
"https://github.com/zhiqwang/yolov5-rt-stack/releases/download/v0.3.0/coco128.zip",
"data/",
)
# 2. Load the model from a checkpoint and use the FiftyOne serializer
model = ObjectDetector.load_from_checkpoint(
"https://flash-weights.s3.amazonaws.com/object_detection_model.pt"
)
model.serializer = FiftyOneDetectionLabels()
# 3. Detect the object on the images
filepaths = [
"data/coco128/images/train2017/000000000025.jpg",
"data/coco128/images/train2017/000000000520.jpg",
"data/coco128/images/train2017/000000000532.jpg",
]
predictions = model.predict(filepaths)
# 4. Visualize predictions
session = visualize(predictions, filepaths=filepaths) |
root = Path(__file__).parent.parent.parent | ||
|
||
|
||
@mock.patch.dict(os.environ, {"FLASH_TESTING": "1"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the same file as tests/core/test_integrations.py
Hey @ehofesmann , awesome work with this integration. |
What does this PR do?
Integrates Lightning Flash with FiftyOne, the open source dataset and model analysis library!
Loading FiftyOne data into Flash
This PR adds
FiftyOneDataSource
s for image/video classification, object detection, semantic segmentation, and image embedding tasks that load FiftyOne Datasets into Flash.Loading Flash predictions into FiftyOne
This PR adds
Serializer
implementations that can convert classification/detection/segmentation model outputs into the appropriate FiftyOne label types so that they can be added to FiftyOne datasets and visualized.Note
This PR requires a source install of FiftyOne on this branch voxel51/fiftyone#1059 in order to function.
git clone https://github.com/voxel51/fiftyone cd fiftyone git checkout --track origin/flash-video bash install.bash
The above branch also contains a parallel integration that enables FiftyOne users to add predictions from any Flash model to their datasets 😄
Points of discussion
It'd be great if these examples could be integrated into the Flash documentation/README in the appropriate places 😄
The new
FiftyoneDataSource
classes introduced in this PR require alabel_field
argument to specify which field of the FiftyOne dataset should be used as the label field. To enable this, we added**data_source_kwargs
to Flash's processor interface. Perhaps there's a better way to support this?When serializing object detections, Flash models seem to return bounding boxes in absolute coordinates, but FiftyOne expects bounding boxes in relative coordinates. Is it possible for
FiftyOneDetectionLabels
to access the dimensions of the current image whenserialize()
is called? Perhaps usingset_state()
as is done for class labels? The current implementation requiresfiftyone.utils.flash.normalize_detections()
to be manually called to convert to relative coordinates for import into FiftyOne, but it would be much cleaner if this could be done natively withinFiftyOneDetectionLabels
...Basic patterns
The following subsections show the basic patterns enabled by this integration. See the next section for concrete examples of each task type.
Loading data from FiftyOne into Flash
FiftyOne users can load their datasets into Flash Data Sources via the pattern below:
Visualizing Flash predictions in FiftyOne
Flash users can swap out the
serializer
on their model with the corresponding FiftyOne serializer for the task type, and then visualize their predictions in the FiftyOne App via the pattern below:Applying Flash models to FiftyOne datasets
In addition to this PR, voxel51/fiftyone#1059 adds a parallel integration in the FiftyOne library that enables FiftyOne users to add predictions from any Flash model to their datasets via the pattern below:
Task examples
The subsections below demonstrate both (a) FiftyOne dataset -> Flash, and (b) Flash predictions -> FiftyOne for each task type.
Video classification
Image classification
Object detection
Semantic segmentation
Image embeddings
Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃